<?php
namespace App\Http\Controllers\Admin;

use App\Models\AnnounceAg;
use App\Models\Announce;
use Illuminate\Support\Facades\Redirect;

class AnnounceAgController extends BaseController
{

    public function __construct(AnnounceAg $announceAg,Announce $announce)
    {
        parent::__construct();
        $this->announceag = $announceAg;
        $this->announce = $announce;
    }
    //系统公告
    public function getIndex()
    {
        //echo '123';die();
        $flag = 'system';
        //$res = $this->announceag->getAnnounceList(request());
        $res = $this->announce->getAnnounceList(request());
        //dd($res);
        return view('agent.notic.notic_list',compact('res','flag'));
    }

    //品牌公告
    public function getAnnounce(){
        $flag = 'announceag';
        $res = $this->announceag->getAnnounceList(request());
        return view('agent.notic.index',compact('res','flag'));
    }

    //发布公告
    public function getAdd()
    {
        $flag = 'announceag';
        $res = $this->announceag->getAnnounceList(request());
        return view('agent.notic.index',compact('res','flag'));
    }

    public function postAdd()
    {
        $res = $this->announceag->addAnnounce(request());

        //dd($res);


        if($res['status']==1){

            return redirect()->back()->with('message', $res['msg'])->withInput();
            //return redirect()->back()->with('errors', '(^_^)!'.$res['msg']);

        }else{

            return redirect()->back()->with('message', $res['msg'])->withInput();
            //return redirect('center/agentlev');
            //return redirect()->back()->with('errors', '提交失败!〒_〒 '.$res['msg']);

        }


    }

    //ajax删除公告
    public function postAnnounceDel()
    {
        $res = $this->announceag->delAnnounceDelById(request());
        return ajax_return($res);
    }


    public function postEdit()
    {
        $res = $this->announceag->editAnnounce(request());
        return ajax_return($res);
    }

    public function postChangeStatus()
    {
        $res = $this->announceag->changeStatus(request());
        return ajax_return($res);
    }
    
}